package com.shell.customer.base.rx;

import com.shell.bee.base.exception.UnCheckMsgException;
import com.shell.bee.base.utils.JsonUtil;
import com.shell.customer.base.CusEvent;
import com.shell.dto.UserAndOrganDto;
import com.shell.feign.UserOrganFeign;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.shell.governor.user.vo.PubUserVo;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PushUserAndOrganForEditSubscriber extends OnErrorNotImplementedSubscriber<CusEvent> {
	@Autowired
	private UserOrganFeign userOrganFeign;

	public void onApplicationEvent(CusEvent event) {
		UserAndOrganDto dto = new UserAndOrganDto();
		List<PubUserVo> users = new ArrayList();

		PubUserVo user = event.getUser();
		user.setNeedSync(true);
		users.add(user);
		dto.setUsers(users);
		dto.setOrgan(event.getOrgan());
		try {
			this.userOrganFeign.saveOrUpdateUserAndOrgan(JsonUtil.toJson(dto));
		} catch (Exception e) {
			e.printStackTrace();
			throw new UnCheckMsgException("������������������������");
		}
	}
}
